// 添加题目
function addQuestion(type) {
	const questionList = document.getElementById('questionList');
	const questionCount = questionList.children.length + 1;
	const typeNames = {
		single: '单选题',
		multiple: '多选题',
		fill: '填空题',
		essay: '问答题'
	};

	const questionItem = document.createElement('div');
	questionItem.className = 'question-item';
	questionItem.innerHTML = `
                <span class="question-handle">≡</span>
                <div class="question-content">${typeNames[type]} ${questionCount}</div>
                <input type="text" class="score-input" placeholder="分值">
                <button type="button" class="delete-btn">删除</button>
            `;

	questionList.appendChild(questionItem);

	questionItem.querySelector('.delete-btn').addEventListener('click', function() {
		questionItem.remove();
	});
}

// Delete question
document.querySelectorAll('.delete-btn').forEach(btn => {
	btn.addEventListener('click', function() {
		this.closest('.question-item').remove();
	});
});

document.getElementById('examForm').addEventListener('submit', function(e) {
	e.preventDefault();
	const formData = {
		name: this.querySelector('input[placeholder="请输入试卷名称"]').value,
		duration: this.querySelector('input[placeholder="请输入考试时长"]').value,
		totalScore: this.querySelector('input[placeholder="请输入试卷总分"]').value,
		passingScore: this.querySelector('input[placeholder="请输入及格分数线"]').value,
		questions: Array.from(document.querySelectorAll('.question-item')).map(item => ({
			type: item.querySelector('.question-content').textContent.split(' ')[0],
			score: item.querySelector('.score-input').value
		}))
	};

	console.log('Form Data:', formData);
	alert('试卷保存成功！');
});